/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ModifyInfo.java
 *
 * Created on 2010-9-29, 21:25:37
 */


package finalsoft;

import Sql.Mysql;
import Sql.User;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;

/**
 *
 * @author lq
 */
public class ModifyInfo extends javax.swing.JPanel {

    /** Creates new form ModifyInfo */
    public ModifyInfo() {
        initComponents();
    }

     public   ModifyInfo(BufferedImage image)   {
               this.image   =   image;
               initComponents();
               
     }
    @Override
    protected   void   paintComponent(Graphics   g)   {
    g.drawImage(image,   0,   0,   this.getWidth(),   this.getHeight(),   this);
     }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jUidTextField = new javax.swing.JTextField();
        jUaddTextField = new javax.swing.JTextField();
        jUemailTextField = new javax.swing.JTextField();
        jUtelTextField = new javax.swing.JTextField();
        jUnameTextField = new javax.swing.JTextField();
        jOtherTextField = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jPasswordField = new javax.swing.JPasswordField();
        jUsexComboBox = new javax.swing.JComboBox();

        setName("Form"); // NOI18N
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });
        addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                formPropertyChange(evt);
            }
        });

        jUidTextField.setEnabled(false);
        jUidTextField.setName("jUidTextField"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(finalsoft.FinalSoftApp.class).getContext().getResourceMap(ModifyInfo.class);
        jUaddTextField.setText(resourceMap.getString("jUaddTextField.text")); // NOI18N
        jUaddTextField.setName("jUaddTextField"); // NOI18N

        jUemailTextField.setText(resourceMap.getString("jUemailTextField.text")); // NOI18N
        jUemailTextField.setName("jUemailTextField"); // NOI18N

        jUtelTextField.setText(resourceMap.getString("jUtelTextField.text")); // NOI18N
        jUtelTextField.setName("jUtelTextField"); // NOI18N

        jUnameTextField.setText(resourceMap.getString("jUnameTextField.text")); // NOI18N
        jUnameTextField.setName("jUnameTextField"); // NOI18N

        jOtherTextField.setText(resourceMap.getString("jOtherTextField.text")); // NOI18N
        jOtherTextField.setName("jOtherTextField"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(finalsoft.FinalSoftApp.class).getContext().getActionMap(ModifyInfo.class, this);
        jButton1.setAction(actionMap.get("submit")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jPasswordField.setText(resourceMap.getString("jPasswordField.text")); // NOI18N
        jPasswordField.setName("jPasswordField"); // NOI18N

        jUsexComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "男", "女" }));
        jUsexComboBox.setName("jUsexComboBox"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(301, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jUsexComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jUtelTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jUemailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jUaddTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jUnameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jUidTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jOtherTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(280, 280, 280))
            .addGroup(layout.createSequentialGroup()
                .addGap(329, 329, 329)
                .addComponent(jButton1)
                .addContainerGap(341, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jOtherTextField, jPasswordField, jUaddTextField, jUemailTextField, jUidTextField, jUnameTextField, jUtelTextField});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(138, Short.MAX_VALUE)
                .addComponent(jUidTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jUnameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jUsexComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(jUaddTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jUemailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jUtelTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jOtherTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addGap(32, 32, 32))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jOtherTextField, jPasswordField, jUaddTextField, jUemailTextField, jUidTextField, jUnameTextField, jUtelTextField});

    }// </editor-fold>//GEN-END:initComponents


    //当面板被显示的时候响应函数
    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        try {                     
            Mysql mysql = new Mysql();
            user = mysql.getUserInfo(LoginPanel.tempUid);         
            
            jUidTextField.setText(user.getUid());
            jUnameTextField.setText(user.getUname()) ;
            jUaddTextField.setText(user.getAddress());
            jPasswordField.setText(user.getPassword());
            jUsexComboBox.setSelectedItem(user.getUsex());
//            jUsexTextField.setText(user.getUsex());
            jUemailTextField.setText(user.getEmail()) ;
            jUtelTextField.setText(user.getTel());
            jOtherTextField.setText(user.getOthers());
        } catch (Exception ex) {}
        
    }//GEN-LAST:event_formComponentShown
//点击提交按钮后 将文本框中的所有内容提交给数据库进行更新
@Action
 public void submit(){
     try{
     user.setUname(jUnameTextField.getText());
     user.setAddress(jUaddTextField.getText());
     user.setEmail(jUemailTextField.getText());
     user.setTel(jUtelTextField.getText());
//     user.setUsex(jUsexTextField.getText());
     user.setUsex(jUsexComboBox.getSelectedObjects()[0].toString());
     user.setPassword(new String(jPasswordField.getPassword()));         
     user.setOthers(jOtherTextField.getText());
     
     Mysql mysql = new Mysql();
//     System.out.print(mysql.updateUserInfo(user));

     System.out.println(user);
     if(mysql.updateUserInfo(user)){
           JOptionPane.showMessageDialog(null, "信息修改成功", "提示", JOptionPane.INFORMATION_MESSAGE );
     }else{
           JOptionPane.showMessageDialog(null, "信息修改失败", "提示", JOptionPane.ERROR_MESSAGE);
     }
     }catch(Exception e){}

 }
    private void formPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_formPropertyChange
        // TODO add your handling code here:       
    }//GEN-LAST:event_formPropertyChange


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JTextField jOtherTextField;
    private javax.swing.JPasswordField jPasswordField;
    private javax.swing.JTextField jUaddTextField;
    private javax.swing.JTextField jUemailTextField;
    private javax.swing.JTextField jUidTextField;
    private javax.swing.JTextField jUnameTextField;
    private javax.swing.JComboBox jUsexComboBox;
    private javax.swing.JTextField jUtelTextField;
    // End of variables declaration//GEN-END:variables
    private   Image   image   =   null;
    private javax.swing.JMenuBar jm;
    private User user;

}
